/**
 *  Encodes input buffer to base64, using OpenSSL BIO
 */
int base64_enc(const unsigned char *input, int length,
        char **out_buf, int *len_out_buf);

/**
  *  Decodes base64 encoded input buffer, using OpenSSL BIO
 */
int base64_dec(unsigned char *input, int length,
        char **out_buf, int *len_out_buf);

/**
 * Save DSA private key to PEM file
 *
 * If strlen(passphrase)>0 encrypt with provided passphrase.
 * Else use default password callback function to get a passphrase
 *
 */
int save_private_key_dsa(const char *filename, const char *passphrase,
        DSA *dsa);

/**
 * Save DSA public key to PEM file
 */
int save_public_key_dsa(const char *filename, DSA *dsa);

/**
 * Generates 2 pem files under the current directory
 */
int generate_DSA_key_pair(const char* passphrase);

/**
 * Load DSA private key from pem file
 */
int load_private_key_dsa(const char *filename, const char *passphrase,
        DSA **dsa);

/**
 * Load DSA public key from pem file
 */
int load_public_key_dsa(const char *filename, DSA **dsa);

/**
 * Calculate SHA1 hash of an input file
 */
int calc_sha1(const char *filename, unsigned char **hash, unsigned int *hash_len);

/**
 * Sign filename with private key from pem file.
 * If passpharase == "", ask for password
 * If sub_msg not null, embed subliminal message in signature!!!
 *
 */
int dsa_sign_file(const char *filename,
        const char *prv_key_pem_file, const char *passphrase,
        const char *sub_msg, int sub_msg_len,
        int leak);


/**
 * Verify signature of given input file and signature file.
 * Use public key from pem file.
 */
int verif_sig_file(const char *filename, const char *sig_file,
        const char *pub_key_pem_file);

/**
 * Extract k from DSA signature, using private key
 */
int dsa_get_k_with_x(const char *filename,
        const char *sig_file,
        const char *prv_key_pem_file,
        const char *passphrase,
        unsigned char **msg );

/**
 * Check if num is quadratic residue modulo m
 */
int is_quad_res(const char *num, const char  *m);
